# core/views.py
from rest_framework.views import APIView
from rest_framework.response import Response
from .models import Banner
from .serializers import BannerSerializer
from django.utils import timezone

class BannerListView(APIView):
    def get(self, request):
        now = timezone.now()
        banners = Banner.objects.filter(
            is_active=True
        ).filter(
            start_time__lte=now if Banner._meta.get_field('start_time').null else now,
            end_time__gte=now if Banner._meta.get_field('end_time').null else now
        ).order_by('order')
        serializer = BannerSerializer(banners, many=True)
        return Response(serializer.data)
